/*
 * 版权所有 (c) 华为技术有限公司 2022-2022
 */
package com.huawei.cameratest.util;

import com.huawei.cameratest.data.StreamConfig;
import com.huawei.cameratest.data.StreamView;

import java.util.ArrayList;
import java.util.List;

public class StreamConfigDB {
    private static StreamConfigDB streamConfigDB = new StreamConfigDB();
    private static List<StreamConfig> streamConfigs = new ArrayList<>();

    private StreamConfigDB() {
    }

    public static StreamConfigDB getInstance() {
        return streamConfigDB;
    }

    public void storeStreamConfig(StreamView[] streamViews, int size) {
        for (int i = 0; i < size; i++) {
            StreamConfig streamConfig = new StreamConfig();
            streamConfig.setStreamId(i);
            String resolution = streamViews[i].getResolution().getSelectedItem().toString();
            streamConfig.setResolution(resolution);
            String encodeBitrate = streamViews[i].getEncodeBitrate().getSelectedItem().toString();
            streamConfig.setEncodeBitrate(encodeBitrate);
            String iframeInterval = streamViews[i].getIframeInterval().getSelectedItem().toString();
            streamConfig.setIframeInterval(iframeInterval);
            String qpMin = streamViews[i].getQualityParamMin().getSelectedItem().toString();
            streamConfig.setQpMin(qpMin);
            String qpMax = streamViews[i].getQualityParamMAX().getSelectedItem().toString();
            streamConfig.setQpMax(qpMax);
            String requestIFrame = streamViews[i].getRequestIFrame().getSelectedItem().toString();
            streamConfig.setRequestIFrame(requestIFrame);
            Object selectedItem = streamViews[i].getSvcMode().getSelectedItem();
            if (selectedItem != null) {
                String svcMode = streamViews[i].getSvcMode().getSelectedItem().toString();
                streamConfig.setSvcMode(svcMode);
            }
            String format = streamViews[i].getFormat().getSelectedItem().toString();
            streamConfig.setFormat(format);
            streamConfigs.add(streamConfig);
        }
    }

    public List<StreamConfig> getStreamConfigs() {
        return streamConfigs;
    }

    public void clearDb() {
        streamConfigs = new ArrayList<>();
    }
}
